/*
 * 描          述:  <描述>
 * 修  改   人:  PengQingyang
 * 修改时间:  2022年5月14日
 * <修改描述:>
 */
package com.tx.component.attachment.context;

import java.util.List;

import org.springframework.beans.factory.InitializingBean;

import com.tx.component.attachment.args.AttachmentDetailAddArgs;
import com.tx.component.attachment.args.AttachmentDetailDeleteArgs;
import com.tx.component.attachment.args.AttachmentDetailQueryArgs;
import com.tx.component.attachment.args.AttachmentDetailSaveArgs;
import com.tx.component.attachment.model.AttachmentDetail;
import com.tx.component.file.context.FileContext;
import com.tx.core.exceptions.util.AssertUtils;
import com.tx.core.paged.model.PagedList;

/**
 * 附件容器实现<br/>
 * <功能详细描述>
 * 
 * @author  PengQingyang
 * @version  [版本号, 2022年5月14日]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class AttachmentContext extends AttachmentContextBuilder
        implements AttachmentEngine, InitializingBean {
    
    /** 文件容器自我引用 */
    public static AttachmentEngine engine;
    
    /**
     * 获取文件容器句柄<br/>
     * <功能详细描述>
     * @return [参数说明]
     * 
     * @return FileContext [返回类型说明]
     * @exception throws [异常类型] [异常说明]
     * @see [类、类#方法、类#成员]
     */
    public static AttachmentEngine getEngine() {
        if (AttachmentContext.engine != null) {
            return AttachmentContext.engine;
        }
        synchronized (FileContext.class) {
            AttachmentContext.engine = applicationContext.getBean(beanName,
                    AttachmentContext.class);
        }
        AssertUtils.notNull(AttachmentContext.engine, "engine is null.");
        
        return AttachmentContext.engine;
    }
    
    /**
     * @param deleteArgs
     */
    @Override
    public void delete(AttachmentDetailDeleteArgs deleteArgs) {
        this.attachmentDetailService.delete(deleteArgs);
    }
    
    /**
     * @param attachmentId
     * @return
     */
    @Override
    public AttachmentDetail findById(String attachmentId) {
        return this.attachmentDetailService.findById(attachmentId);
    }
    
    /**
     * @param relativePath
     * @param catalog
     * @return
     */
    @Override
    public AttachmentDetail findByRelativePath(String relativePath,
            String catalog) {
        return this.attachmentDetailService.findByRelativePath(relativePath,
                catalog);
    }
    
    /**
     * @param queryArgs
     * @return
     */
    @Override
    public int count(AttachmentDetailQueryArgs queryArgs) {
        return this.attachmentDetailService.count(queryArgs);
    }
    
    /**
     * @param queryArgs
     * @return
     */
    @Override
    public List<AttachmentDetail> list(AttachmentDetailQueryArgs queryArgs) {
        return this.attachmentDetailService.list(queryArgs);
    }
    
    /**
     * @param queryArgs
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @Override
    public PagedList<AttachmentDetail> pages(
            AttachmentDetailQueryArgs queryArgs, int pageIndex, int pageSize) {
        return this.attachmentDetailService
                .pages(queryArgs, pageIndex, pageSize);
    }
    
    /**
     * @param catalog
     * @param saveArgs
     * @return
     */
    @Override
    public AttachmentDetail save(String catalog,
            AttachmentDetailSaveArgs saveArgs) {
        return this.attachmentDetailService.save(catalog, saveArgs);
    }
    
    /**
     * @param catalog
     * @param addArgs
     * @return
     */
    @Override
    public AttachmentDetail add(String catalog,
            AttachmentDetailAddArgs addArgs) {
        return this.attachmentDetailService.add(catalog, addArgs);
    }
}
